home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Credits2.aspx.cs114 < prev    next >
Text File  |  2008-03-01  |  22KB  |  524 lines

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.Caching;
  6. using System.Web.UI;
  7. using GBPVR.Public;
  8. using GBPVRSchedule;
  9. using gbweb.classes;
  10.  
  11. namespace gbweb
  12. {
  13.     /// <summary>
  14.     /// Summary description for Credits.
  15.     /// </summary>
  16.     public partial class Credits2 : Page
  17.     {
  18.  
  19.         protected string programUniqueIdentifier;
  20.         private const string hdrActors = "<div class=\"headerRow\">Actors</div>\n";
  21.         private const string hdrDirectors = "<div class=\"headerRow\">Directors</div>\n";
  22.         private const string hdrExecProd = "<div class=\"headerRow\">Executive Producers</div>\n";
  23.         private const string hdrProducers = "<div class=\"headerRow\">Producers</div>\n";
  24.         private const string hdrWriters = "<div class=\"headerRow\">Writers</div>\n";
  25.         private const string hdrGuestStars = "<div class=\"headerRow\">Guest Stars</div>\n";
  26.         private const string hdrHosts = "<div class=\"headerRow\">Hosts</div>\n";
  27.         private const string hdrNarrators = "<div class=\"headerRow\">Narrators</div>\n";
  28.         private const string hdrJudges = "<div class=\"headerRow\">Judges</div>\n";
  29.         private const string hdrContestants = "<div class=\"headerRow\">Contestants</div>\n";
  30.         private const string hdrGuests = "<div class=\"headerRow\">Guests</div>\n";
  31.         
  32.     
  33.         protected void Page_Load(object sender, EventArgs e)
  34.         {
  35.             getTheme();
  36.             
  37.             if (!IsPostBack) 
  38.             {
  39.                 Schedule scheduleHelper = Global.Schedule;
  40.  
  41.                 Programme programme = scheduleHelper.GetProgrammeByOID(int.Parse(Request.Params["id"]));
  42.                 // show programme details
  43.                 showTitle.Text = programme.getTitle();
  44.                 programUniqueIdentifier = programme.getUniqueProgrammeIdentifier();
  45.                 showSubTitle.Text = programme.getSubTitle();
  46.                 if (showSubTitle.Text.Length <1 )
  47.                 {
  48.                     EPISODE_SUBTITLE.Visible = false;
  49.                 }
  50.                 else
  51.                 {
  52.                     EPISODE_SUBTITLE.Visible = true; 
  53.                 }
  54.  
  55.                 bool ExtendedEWAEnabled = ExtendedEWA.Initialize();
  56.  
  57.                 string description = DetailDisplay2.getDetailDisplay(programme);
  58.  
  59.                 if (ExtendedEWAEnabled)
  60.                 {
  61.                     //Open the ExtendedEWA DB
  62.                     ExtendedEWA.OpenExtendedEWADB();
  63.  
  64.                     //Pull all the cast/crew found for the show
  65.                     ArrayList cast = ExtendedEWA.GetCast(programme.getUniqueProgrammeIdentifier());
  66.  
  67.                     //Close the ExtendedEWA DB
  68.                     ExtendedEWA.CloseExtendedEWADB();
  69.  
  70.                     //If any cast was found load up the information
  71.                     if (cast.Count > 0)
  72.                     {
  73.                         //Create the table arrays to hold any found crew
  74.                         ArrayList actors        = new ArrayList();
  75.                         ArrayList directors        = new ArrayList();
  76.                         ArrayList producers        = new ArrayList();
  77.                         ArrayList writers        = new ArrayList();
  78.                         ArrayList execProducers = new ArrayList();
  79.                         ArrayList guestStars    = new ArrayList();
  80.                         ArrayList hosts            = new ArrayList();
  81.                         ArrayList narrators     = new ArrayList();
  82.                         ArrayList judges         = new ArrayList();
  83.                         ArrayList contestants = new ArrayList();
  84.                         ArrayList guests = new ArrayList();
  85.  
  86.                         foreach (ExtendedEWA.Crew crew in cast)
  87.                         {
  88.                             switch (crew.Role)
  89.                             {
  90.                                 case ExtendedEWA.Role.Actor:
  91.                                     actors.Add(crew);
  92.                                     break;
  93.                                 case ExtendedEWA.Role.Director:
  94.                                     directors.Add(crew);
  95.                                     break;
  96.                                 case ExtendedEWA.Role.Producer:
  97.                                     producers.Add(crew);
  98.                                     break;
  99.                                 case ExtendedEWA.Role.Writer:
  100.                                     writers.Add(crew);
  101.                                     break;
  102.                                 case ExtendedEWA.Role.ExecProducer:
  103.                                     execProducers.Add(crew);
  104.                                     break;
  105.                                 case ExtendedEWA.Role.GuestStar:
  106.                                     guestStars.Add(crew);
  107.                                     break;
  108.                                 case ExtendedEWA.Role.Host:
  109.                                     hosts.Add(crew);
  110.                                     break;
  111.                                 case ExtendedEWA.Role.Narrator:
  112.                                     narrators.Add(crew);
  113.                                     break;
  114.                                 case ExtendedEWA.Role.Judge:
  115.                                     judges.Add(crew);
  116.                                     break;
  117.                                 case ExtendedEWA.Role.Contestant:
  118.                                     contestants.Add(crew);
  119.                                     break;
  120.                                 case ExtendedEWA.Role.Guest:
  121.                                     guests.Add(crew);
  122.                                     break;
  123.                             }
  124.                         }
  125.                     
  126.                         //Load the data
  127.                         ArrayList foundCrew = new ArrayList();
  128.  
  129.                         if (actors.Count > 0)
  130.                         {
  131.                             foundCrew.Add(1);
  132.                         }
  133.                         else
  134.                         {
  135.                             ACTORS.Visible = false;
  136.                         }
  137.                         if (directors.Count > 0)
  138.                         {
  139.                             foundCrew.Add(2);
  140.                         }
  141.                         else
  142.                         {
  143.                             DIRECTORS.Visible = false;
  144.                         }
  145.                         if (producers.Count > 0)
  146.                         {
  147.                             foundCrew.Add(3);
  148.                         }
  149.                         else
  150.                         {
  151.                             PRODUCERS.Visible = false;
  152.                         }
  153.                         if (writers.Count > 0)
  154.                         {
  155.                             foundCrew.Add(4);
  156.                         }
  157.                         else
  158.                         {
  159.                             WRITERS.Visible = false;
  160.                         }
  161.                         if (execProducers.Count > 0)
  162.                         {
  163.                             foundCrew.Add(5);
  164.                         }
  165.                         else
  166.                         {
  167.                             EXEC_PRODUCERS.Visible = false;
  168.                         }
  169.                         if (guestStars.Count > 0)
  170.                         {
  171.                             foundCrew.Add(6);
  172.                         }
  173.                         else
  174.                         {
  175.                             GUEST_STARS.Visible = false;
  176.                         }
  177.                         if (narrators.Count > 0)
  178.                         {
  179.                             foundCrew.Add(7);
  180.                         }
  181.                         else
  182.                         {
  183.                             NARRATORS.Visible = false;
  184.                         }
  185.                         if (judges.Count > 0)
  186.                         {
  187.                             foundCrew.Add(8);
  188.                         }
  189.                         else
  190.                         {
  191.                             JUDGES.Visible = false;
  192.                         }
  193.                         if (hosts.Count > 0)
  194.                         {
  195.                             foundCrew.Add(9);
  196.                         }
  197.                         else
  198.                         {
  199.                             HOSTS.Visible = false;
  200.                         }
  201.                         if (contestants.Count > 0)
  202.                         {
  203.                             foundCrew.Add(10);
  204.                         }
  205.                         else
  206.                         {
  207.                             CONTESTANTS.Visible = false;
  208.                         }
  209.                         if (guests.Count > 0)
  210.                         {
  211.                             foundCrew.Add(11);
  212.                         }
  213.                         else
  214.                         {
  215.                             GUESTS.Visible = false;
  216.                         }
  217.  
  218.                         string styleWidth1 = string.Empty;
  219.                         string styleWidth2 = string.Empty;
  220.                         switch (foundCrew.Count)
  221.                         {
  222.                             case 0:
  223.                                 break;
  224.                             case 1:
  225.                                 styleWidth1 = "99%";
  226.                                 styleWidth2 = "99%";
  227.                                 break;
  228.                             case 2:
  229.                                 styleWidth1 = "49%";
  230.                                 styleWidth2 = "50%";
  231.                                 break;
  232.                             case 3:
  233.                                 styleWidth1 = "33%";
  234.                                 styleWidth2 = "33%";
  235.                                 break;
  236.                             case 4:
  237.                                 styleWidth1 = "24%";
  238.                                 styleWidth2 = "27%";
  239.                                 break;
  240.                             case 5:
  241.                                 styleWidth1 = "19%";
  242.                                 styleWidth2 = "23%";
  243.                                 break;
  244.                             case 6:
  245.                                 styleWidth1 = "16%";
  246.                                 styleWidth2 = "19%";
  247.                                 break;
  248.                             case 7:
  249.                                 styleWidth1 = "14%";
  250.                                 styleWidth2 = "15%";
  251.                                 break;
  252.                             case 8:
  253.                                 styleWidth1 = "12%";
  254.                                 styleWidth2 = "15";
  255.                                 break;
  256.                             case 9:
  257.                                 styleWidth1 = "11%";
  258.                                 styleWidth2 = "11%";
  259.                                 break;
  260.                             case 10:
  261.                                 styleWidth1 = "10%";
  262.                                 styleWidth2 = "9%";
  263.                                 break;
  264.                             case 11:
  265.                                 styleWidth1 = "9%";
  266.                                 styleWidth2 = "9%";
  267.                                 break;
  268.                         }
  269.                         string styleWidth = styleWidth1;
  270.                         string border = "\"none\"";
  271.                         for (int a = 0; a < foundCrew.Count; a++)
  272.                         {
  273.                             if (a == (foundCrew.Count - 1))
  274.                             {
  275.                                 styleWidth = styleWidth2;
  276.                                 border = "\"1px solid #000000\"";
  277.                             }
  278.  
  279.                             switch ((int) foundCrew[a])
  280.                             {
  281.                                 case 1:
  282.                                     ACTORS.Style.Add("width", styleWidth);
  283.                                     ACTORS.Style.Add("border-right", border);
  284.                                     ACTORS.InnerHtml = fillDiv(actors, hdrActors);
  285.                                     break;
  286.                                 case 2:
  287.                                     DIRECTORS.Style.Add("width", styleWidth);
  288.                                     DIRECTORS.Style.Add("border-right", border);
  289.                                     DIRECTORS.InnerHtml = fillDiv(directors, hdrDirectors);
  290.                                     break;
  291.                                 case 3:
  292.                                     PRODUCERS.Style.Add("width", styleWidth);
  293.                                     PRODUCERS.Style.Add("border-right", border);
  294.                                     PRODUCERS.InnerHtml = fillDiv(producers, hdrProducers);
  295.                                     break;
  296.                                 case 4:
  297.                                     WRITERS.Style.Add("width", styleWidth);
  298.                                     WRITERS.Style.Add("border-right", border);
  299.                                     WRITERS.InnerHtml = fillDiv(writers, hdrWriters);
  300.                                     break;
  301.                                 case 5:
  302.                                     EXEC_PRODUCERS.Style.Add("width", styleWidth);
  303.                                     EXEC_PRODUCERS.Style.Add("border-right", border);
  304.                                     EXEC_PRODUCERS.InnerHtml = fillDiv(execProducers, hdrExecProd);
  305.                                     break;
  306.                                 case 6:
  307.                                     GUEST_STARS.Style.Add("width", styleWidth);
  308.                                     GUEST_STARS.Style.Add("border-right", border);
  309.                                     GUEST_STARS.InnerHtml = fillDiv(guestStars, hdrGuestStars);
  310.                                     break;
  311.                                 case 7:
  312.                                     NARRATORS.Style.Add("width", styleWidth);
  313.                                     NARRATORS.Style.Add("border-right", border);
  314.                                     NARRATORS.InnerHtml = fillDiv(narrators, hdrNarrators);
  315.                                     break;
  316.                                 case 8:
  317.                                     JUDGES.Style.Add("width", styleWidth);
  318.                                     JUDGES.Style.Add("border-right", border);
  319.                                     JUDGES.InnerHtml = fillDiv(judges, hdrJudges);
  320.                                     break;
  321.                                 case 9:
  322.                                     HOSTS.Style.Add("width", styleWidth);
  323.                                     HOSTS.Style.Add("border-right", border);
  324.                                     HOSTS.InnerHtml = fillDiv(hosts, hdrHosts);
  325.                                     break;
  326.                                 case 10:
  327.                                     CONTESTANTS.Style.Add("width", styleWidth);
  328.                                     CONTESTANTS.Style.Add("border-right", border);
  329.                                     CONTESTANTS.InnerHtml = fillDiv(contestants, hdrContestants);
  330.                                     break;
  331.                                 case 11:
  332.                                     GUESTS.Style.Add("width", styleWidth);
  333.                                     GUESTS.Style.Add("border-right", border);
  334.                                     GUESTS.InnerHtml = fillDiv(guests, hdrGuests);
  335.                                     break;
  336.                             }
  337.                         }
  338.                     }
  339.                     else
  340.                     {
  341.                         CREDITS.InnerHtml = "<span class=\"infoTitle\">No Credit Information Available For This Programme.</span>";
  342.                     }
  343.                 }
  344.  
  345.                 
  346.                 //Load the show description/date/channel
  347.                 desc.InnerHtml = description;
  348.  
  349.                 showStartDate.Text = programme.getStartTime().ToLongDateString();
  350.                 //showTimes.Text = programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString();
  351.  
  352.                 Channel channel = scheduleHelper.GetChannelByOID(programme.getChannelOID());
  353.                 
  354.                 if (channel != null)
  355.                 {
  356.                     string channelName = channel.getName();
  357.                     if (channelName.StartsWith(channel.getChannelNumber().ToString()))
  358.                         // cosmetic stuff for my american friends
  359.                     {
  360.                         channelName = channelName.Substring(channel.getChannelNumber().ToString().Length);
  361.                     }
  362.                     showChannelNumber.Text = channel.getChannelNumber().ToString();
  363.                     showChannelName.Text = channelName;
  364.                     string channelIcon = GetChannelIcon(channel.getChannelNumber(), new string[] { channel.getName(), channelName });
  365.                     if (channelIcon != null)
  366.                     {
  367.                         CHANNEL_ICON.InnerHtml = "<img src=\"" + Download.GetDownloadUrl(false, true, Download.InternalFiles.ChannelIcon, Server.UrlEncode(channelIcon)) + "\" alt=\"\" width=\"67\" height=\"50\" hspace=\"0\" vspace=\"0\" border=\"1\" runat=\"server\">";
  368.                     }
  369.                     else
  370.                     {
  371.                         CHANNEL_ICON.Visible = false;
  372.                     }
  373.                 }
  374.                 else
  375.                 {
  376.                     CHANNEL_ICON.Visible = false;
  377.                 }
  378.             }
  379.         }
  380.  
  381.         private static string fillDiv(ArrayList crewlist, string hdr)
  382.         {
  383.             string div = hdr;
  384.             div += "<div class=\"listings\">";
  385.             string innerInfo = string.Empty;
  386.             while (crewlist.Count > 0)
  387.             {
  388.                 ExtendedEWA.Crew crew = (ExtendedEWA.Crew)crewlist[0];
  389.                 crewlist.Remove(crew);
  390.  
  391.                 innerInfo += "<a href=\"http://www.imdb.com/find?s=all&q=" + crew.GivenName + "+" + crew.SurName + "\" onclick=\"EditPop2(this,'IMDB');return false;\" class=\"cellItem\">" + crew.GivenName + " " + crew.SurName + "</a><br>\n";
  392.             }
  393.             div += innerInfo + "</div>\n";
  394.             return div;
  395.         }
  396.  
  397.         private void getTheme()
  398.         {
  399.             string theme = Convert.ToString(Session["theme"]);
  400.  
  401.             if (theme != null && theme != "")
  402.             {
  403.                 return;
  404.             }
  405.             else
  406.             {
  407.                 HttpCookie cookie = Request.Cookies["theme"];
  408.                 if (cookie != null && cookie.Value.Length > 0)
  409.                 {
  410.                     theme = cookie.Value;
  411.                 }
  412.                 else
  413.                 {
  414.                     theme = "Default";
  415.                 }
  416.                 Session["theme"] = "themes/" + theme;
  417.                 return;
  418.             }
  419.         }
  420.  
  421.         private static string channelIconPath;
  422.         private static string[] channelIconExtensions;
  423.  
  424.         public string GetChannelIcon(int channelNumber, string[] channelNames)
  425.         {
  426.             // Get the Channel Icon Directory
  427.             if (channelIconPath == null)
  428.             {
  429.                 lock (typeof(Credits2))
  430.                 {
  431.                     if (channelIconPath == null)
  432.                     {
  433.                         channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
  434.                         channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
  435.                     }
  436.                 }
  437.             }
  438.  
  439.             Hashtable channelIconCache = (Hashtable)Cache["channelIconCache"];
  440.             if (channelIconCache == null)
  441.             {
  442.                 lock (typeof(Credits2))
  443.                 {
  444.                     channelIconCache = (Hashtable)Cache["channelIconCache"];
  445.                     if (channelIconCache == null)
  446.                     {
  447.                         channelIconCache = new Hashtable();
  448.                         Cache.Add(
  449.                             "channelIconCache",
  450.                             channelIconCache,
  451.                             new CacheDependency(channelIconPath),
  452.                             DateTime.MaxValue,
  453.                             //DateTime.Now.AddMinutes(30),
  454.                             //TimeSpan.Zero,
  455.                             Cache.NoSlidingExpiration,
  456.                             CacheItemPriority.Normal,
  457.                             null);
  458.                     }
  459.                 }
  460.             }
  461.  
  462.             if (channelIconCache.ContainsKey(channelNumber))
  463.             {
  464.                 return (string)channelIconCache[channelNumber];
  465.             }
  466.  
  467.             lock (channelIconCache)
  468.             {
  469.                 if (channelIconCache.ContainsKey(channelNumber))
  470.                 {
  471.                     return (string)channelIconCache[channelNumber];
  472.                 }
  473.  
  474.                 string channelIconFile = null;
  475.                 foreach (string channelName in channelNames)
  476.                 {
  477.                     foreach (string channelIconExtension in channelIconExtensions)
  478.                     {
  479.                         string cleanName = channelName;
  480.                         string channelNameWork = channelName;
  481.                         while (cleanName.Contains("/"))
  482.                         {
  483.                             if (channelNameWork.Contains("/"))
  484.                             {
  485.                                 cleanName = channelNameWork.Remove(channelNameWork.IndexOf("/"), 1);
  486.                                 channelNameWork = cleanName;
  487.                             }
  488.                         }
  489.                         string probeFile = cleanName  + "." + channelIconExtension;
  490.                         if (File.Exists(Path.Combine(channelIconPath, probeFile)))
  491.                         {
  492.                             channelIconFile = probeFile;
  493.                             break;
  494.                         }
  495.                     }
  496.                     if (channelIconFile != null) break;
  497.                 }
  498.                 channelIconCache[channelNumber] = channelIconFile;
  499.                 return channelIconFile;
  500.             }
  501.         }
  502.  
  503.         #region Web Form Designer generated code
  504.         override protected void OnInit(EventArgs e)
  505.         {
  506.             //
  507.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  508.             //
  509.             InitializeComponent();
  510.             base.OnInit(e);
  511.         }
  512.         
  513.         /// <summary>
  514.         /// Required method for Designer support - do not modify
  515.         /// the contents of this method with the code editor.
  516.         /// </summary>
  517.         private void InitializeComponent()
  518.         {    
  519.  
  520.         }
  521.         #endregion
  522.     }
  523. }
  524.